import {
	request,
	requestData
} from "../Promise.js"
import indexApi from "./index.js"
// 安全码
import safetyCode from "./safety-code.js"
// 信息查询
import searchApi from "./search.js"
// 知识库
import knowBase from "./know-base.js"
// 在线学习
import onLineStudy from "./on-line-study.js"
import {
	formDataInit
} from '../util.js'
export default {
	/**
	 * @param sysType 移动端类型  1：android  2：IOS
	 * @param vInfo 版本信息 （年.月.次版本号.修订号）
	 * @param appType app类型  1：企业端app  2:监督手机管理app
	 */
	getNewByApp(sysType, vInfo, appType) {
		return request({
			url: '/data-dispatch/appUpgrade/getNewByApp',
			method: 'get',
			data: {
				sysType,
				vInfo,
				appType
			}
		})
	},
	//登录
	login(data, header) {
		return request({
			url: '/blade-auth/oauth/token?tenantId=' + data.tenantId + "&username=" + data.username +
				"&password=" +
				data.password + "&grant_type=" + data.grant_type + "&scope=" + data.scope + "&type=" + data
				.type,
			method: 'post',
		})
	},


	// 修改密码
	updatePassword(data) {
		return request({
			url: '/blade-user/update-password?oldPassword=' + data.oldPassword + '&newPassword=' + data
				.newPassword + '&newPassword1=' + data.newPassword1,
			method: 'post',
			data

		})
	},

	// 获取机构
	getDeptTreeById(deptId) {
		return request({
			url: '/blade-system/dept/getDeptTree?deptId=' + deptId,
			method: 'get',
		})
	},



	// 手机号注册
	sendValidate(data) {
		return request({
			url: 'blade-user/infoServer/reset/sendValidate?phone=' + data,
			method: 'post',
		})
	},

	// 根据企业名称查询企业信息
	findOwner(ownerName) {
		return request({
			url: '/blade-user/baseowner/findOwner',
			method: 'get',
			params: {
				ownerName
			}
		})
	},

	getTree(list) {
		const res = [];
		if (!list || list.length == 0) return res;
		for (const item of list) {
			const o = {
				name: item.dictValue,
				id: item.dictKey
			};
			if (item.children && item.children.length) {
				o.children = getTree(item.children);
			}
			res.push(o);
		}
		return res;
	},

	getDictByCode(code) {
		return new Promise((resolve) => {
			request({
				url: `/blade-system/dict-biz/dictionary?code=${code}`,
				method: 'get',

			}).then(res => {
				resolve(this.getTree(res.data.data))
			})
		})
	},

	getDict(code) {
		return request({
			url: `/blade-system/dict/dictionary?code=${code}`,
			method: 'get',
		})
	},


	// 根据企业名称查询企业信息
	getDeptUserList(deptId, tenantId) {
		return request({
			url: '/blade-user/getDeptUserList?deptId=' + deptId + '&tenantId=' + tenantId,
			method: 'get',
		})
	},


	// 课程列表
	getCourse(data) {
		return request({
			url: '/data-inspection-study/hg-app/study-lesson/info',
			method: 'post',
			data
		})
	},

	// 课程详情
	getDetails(id) {
		return request({
			url: `/data-inspection-study/hg-app/study-lesson/info/${id}`,
			method: 'post',
		})
	},

	// 保存学习进度
	saveStudy(data) {
		return request({
			url: '/data-inspection-study/hg-app/study-record/save',
			method: 'post',
			data: data,
			header: {
				'content-type': "application/x-www-form-urlencoded",
			}
		})
	},


	// 学习记录(学员角色)
	getStudyRecord(data) {
		return request({
			url: '/data-inspection-study/hg-app/class-person/user-page',
			method: 'post',
			data
		})
	},

	// 我的测验列表
	getTestList(data) {
		return request({
			url: '/data-inspection-study/hg-app/exam-record/page',
			method: 'post',
			data
		})
	},

	// 开始挑战
	beganChallenge(data) {
		return request({
			url: '/data-inspection-study/hg-app/exam-record/start',
			method: 'post',
			data
		})
	},


	// 查看结果
	viewResults(data) {
		return request({
			url: '/data-inspection-study/hg-app/exam-record/info',
			method: 'post',
			data
		})
	},

	// 保存考试进度
	saveTest(data) {
		return request({
			url: '/data-inspection-study/hg-app/exam-recorditem/save',
			method: 'post',
			data
		})
	},

	// 交卷
	carryTest(data) {
		return request({
			url: '/data-inspection-study/hg-app/exam-recorditem/submit',
			method: 'post',
			data
		})
	},

	// 重新考试
	queryTest(data) {
		return request({
			url: '/data-inspection-study/hg-app/exam-record/again',
			method: 'post',
			data
		})
	},

	//监测分析
	//重点监管货物类别流量统计
	focusGoodsCategory(params) {
		return request({
			url: '/data-statisanalysis/flow/focusGoodsCategory',
			method: 'get',
			params
		})
	},
	//流量流向统计
	directionStatistics(params) {
		return request({
			url: '/data-statisanalysis/flow/directionStatistics',
			method: 'get',
			params
		})
	},
	//货物流入流出统计排名
	goodsFlowRank(params) {
		return request({
			url: '/data-statisanalysis/flow/goodsFlowRank',
			method: 'get',
			params
		})
	},
	//货物线路
	lineGoodsWeightCount(params) {
		return request({
			url: '/data-statisanalysis/flow/lineGoodsWeightCount',
			method: 'get',
			params
		})
	},
	//货物种类
	goodsTypeTop(params) {
		return request({
			url: '/data-statisanalysis/flow/goodsTypeTop',
			method: 'get',
			params
		})
	},
	//运行监测分析
	cityDetail(params) {
		return request({
			url: '/data-statisanalysis/home/cityDetail',
			method: 'get',
			params
		})
	},
	//运行监测分析
	cityAllRate(params) {
		return request({
			url: '/data-statisanalysis/home/cityAllRate',
			method: 'get',
			params
		})
	},
	// 逆地理解析
	getAddress(params) {
		return request({
			url: 'https://restapi.amap.com/v3/geocode/regeo',
			method: 'get',
			hideLoad: true,
			data: {
				key: 'a5b6c60bf58424fbaaf0f4955ac9058a',
				output: 'json',
				location: params,
			}
		})
	},
	...onLineStudy,
	...knowBase,
	...safetyCode,
	...searchApi,
	...indexApi,
}